package Algorithms;

public class InsertionSort {
	
	int length;
	int [] arrayToSort;
	
	public void sort(int []array){
		
		this.length = array.length;
		this.arrayToSort = array;
		insertionsort();
	}
	
	public void insertionsort(){
		
		int key, j;
		for (int i = 1; i <length; i ++){
			
			key = arrayToSort[i];
			j = i -1;
			while (j > 0 && arrayToSort[j] > key){
				arrayToSort[j+1] = arrayToSort[j];
				j--;
			}
			arrayToSort[j + 1] = key;
		}
	}
	
	public void printRes(){
		
		for (int i = 0; i < length; i++)
			System.out.println(arrayToSort[i]);
	}
}
